package com.cowin.inf.controller;

import com.cowin.base.result.Result;
import com.cowin.base.result.ResultGenerator;
import com.cowin.base.BaseController;
import com.cowin.inf.model.KyBdcVehicle;
import com.cowin.inf.service.KyBdcVehicleService;
import com.cowin.sys.model.vo.HoldVehicle;
import com.cowin.sys.model.vo.OnLineMakeVehicle;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by  on 2020/03/20.
 *
 * @author CodeGenerator
 */
@Slf4j
@RestController
@RequestMapping("/ky/bdc/vehicle")
public class KyBdcVehicleController extends BaseController<KyBdcVehicle> {
    @Resource
    private KyBdcVehicleService kyBdcVehicleService;


    @ApiOperation(value = "BDC在制车辆", notes = "BDC在制车辆")
    @PostMapping("/online")
    public Result hzOnLineMake(@RequestBody HoldVehicle holdVehicle) {
        Map<String,Object> map = new HashMap<>();
        kyBdcVehicleService.updateStateByPointAndVin();
        if(holdVehicle.getPage()!=-1&&holdVehicle.getLimit()!=-1){
            //查询焊装BDC
            PageHelper.startPage(holdVehicle.getPage(), holdVehicle.getLimit());
            List<OnLineMakeVehicle> k2List = kyBdcVehicleService.findByPoint("K2", holdVehicle.getVin());
            PageInfo<OnLineMakeVehicle> k2ListListInfo = new PageInfo<>(k2List);
            map.put("k2List", k2ListListInfo);
            //查询途BDC
            PageHelper.startPage(holdVehicle.getPage(), holdVehicle.getLimit());
            List<OnLineMakeVehicle> p1List = kyBdcVehicleService.findByPoint("P1", holdVehicle.getVin());
            PageInfo<OnLineMakeVehicle> p1LististInfo = new PageInfo<>(p1List);
            map.put("p1List", p1LististInfo);
            //查询BDC总装10点
            PageHelper.startPage(holdVehicle.getPage(), holdVehicle.getLimit());
            List<OnLineMakeVehicle> pbsList = kyBdcVehicleService.findPbs("P11", holdVehicle.getVin());
            PageInfo<OnLineMakeVehicle> pbsListInfo = new PageInfo<>(pbsList);
            map.put("pbsList", pbsListInfo);
        }else {
            List<OnLineMakeVehicle> k2List = kyBdcVehicleService.findByPoint("K2", holdVehicle.getVin());
            List<OnLineMakeVehicle> p1List = kyBdcVehicleService.findByPoint("P1", holdVehicle.getVin());
            List<OnLineMakeVehicle> pbsList = kyBdcVehicleService.findPbs("P11", holdVehicle.getVin());
            map.put("k2List", k2List);
            map.put("p1List", p1List);
            map.put("pbsList", pbsList);
        }
        return ResultGenerator.genSuccessResult(map);

    }
}
